package ru.pb.auth.data.xml.holders;

import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import ru.pb.auth.model.GameServerInfo;
import ru.pb.global.xml.holder.AbstractHolder;

/**
 * Author: Felixx
 */
public class GameServersHolder extends AbstractHolder
{
	private static GameServersHolder _instance;

	private final Map<Integer, GameServerInfo> _gameServerTable = new TreeMap<Integer, GameServerInfo>();

	public static GameServersHolder getInstance()
	{
		if(_instance == null)
			_instance = new GameServersHolder();
		return _instance;
	}

	private GameServersHolder()
	{}

	@Override
	public int size()
	{
		return _gameServerTable.size();
	}

	@Override
	public void clear()
	{}

	public void add(GameServerInfo gameServerInfo)
	{
		_gameServerTable.put(gameServerInfo.getId(), gameServerInfo);
	}

	public void remove(GameServerInfo gameServerInfo)
	{
		_gameServerTable.remove(gameServerInfo.getId());
	}

	public GameServerInfo getGameServerInfo(int id)
	{
		return _gameServerTable.get(id);
	}

	public Collection<GameServerInfo> getGameServers()
	{
		return _gameServerTable.values();
	}
}